﻿using System;
using SharpShare.Storage.FileSystem.Configuration;

namespace SharpShare.Storage.FileSystem {
    [Serializable]
    //[StorageProviderModel(
    //    "File System",
    //    Description = "Provides access to the file system.")]
    public sealed class FileStorageOptions : ICloneable, IEquatable<FileStorageOptions> {
        [NonSerialized]
        private IFileMetadataProvider _metadataProvider;

        public FileStorageOptions() {
            this.MetadataProvider = NtfsFileMetadataProvider.Provider;
        }

        public string RootPath { get; set; }
        public string RootName { get; set; }

        public IFileMetadataProvider MetadataProvider {
            get { return _metadataProvider; }
            set { _metadataProvider = value; }
        }

        public FileStorageOptions Clone() {
            return (FileStorageOptions)this.MemberwiseClone();
        }

        #region ICloneable Members

        object ICloneable.Clone() {
            return this.Clone();
        }

        #endregion

        #region IEquatable<FileStorageOptions> Members

        public bool Equals(FileStorageOptions other) {
            if (other == null) return false;

            return this.CreateTuple().Equals(other.CreateTuple());
        }

        #endregion

        public override bool Equals(object obj) {
            return this.Equals(obj as FileStorageOptions);
        }
        public override int GetHashCode() {
            return CreateTuple().GetHashCode();
        }

        private Tuple<string, string, IFileMetadataProvider> CreateTuple() {
            return Tuple.Create(this.RootPath, this.RootName, this.MetadataProvider);
        }
    }
}
